package md5

import (
	"crypto/md5"
	"fmt"
	"strings"
	log "ac-common-go/glog"
)

func CheckMd5(_encryptstr, _md5str string) (ret bool) {
	//方法一
	has := md5.Sum([]byte(_encryptstr))
	md5str1 := fmt.Sprintf("%x", has) //将[]byte转成16进制
	cmpstr := md5str1[8:24]
	log.Info("CHECK MD5[%s]", cmpstr)
	if strings.Compare(cmpstr, _md5str) == 0 {
		ret = true
	} else {
		ret = false
	}
	return ret
}
func Md5Encode(_encryptstr string) (_encoderet string, err error) {
	has := md5.Sum([]byte(_encryptstr))
	md5str1 := fmt.Sprintf("%x", has) //将[]byte转成16进制
	_encoderet = md5str1[8:24]
	return _encoderet, nil
}
